<%@page language="java" isELIgnored="false" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<jsp:directive.include file="/WEB-INF/sitemesh-decorators/include.jsp"/>
<fmt:setBundle basename="bundles.thesis-resources"/>
<head>
<script type="text/javascript">
var tempStr2="";
$(function() {
	var categoryList = '${facultyList}';
	var catStr = categoryList.substring(categoryList.indexOf('{')+1,categoryList.indexOf('}'));
	catStr = catStr.replace(/=/g,":");
	//alert(catStr);
	var categoryArr=catStr.split(',');
	var tempArray = new Array();
	var tempStr="";
	for(var i=0;i<categoryArr.length;i++){
		//categoryArr[i] = categoryArr[i].replace(/\|/,",");
		tempStr = categoryArr[i];
		tempStr = tempStr.substring(tempStr.indexOf(":")+1);
		//alert(tempStr);
		tempArray[i]= tempStr;
	}
	var tempStr1="";
	
	$( "#facultyText").autocomplete({
		//source: categoryArr,
		source: tempArray,
		//define select handler
		select: function(e, ui) {
			//create formatted data
			var cat = ui.item.value;
			getId(cat,categoryArr,'faculty');
			
			$("#facultyText").val(cat);
			//tempStr1 = cat.substring(cat.indexOf(":")+1);
			//alert(tempStr1);
			//tempStr2 = cat.substring(0,cat.indexOf(":"));
			//alert(tempStr2);
		},
		close: function(event, ui) {
			
			
		}
	});
	
	var categoryList2 = '${researchkeywordList}';
	var catStr2 = categoryList2.substring(categoryList2.indexOf('{')+1,categoryList2.indexOf('}'));
	catStr2 = catStr2.replace(/=/g,":");
	//alert(catStr);
	var categoryArr2=catStr2.split(',');
	var tempArray2 = new Array();
	var tempStr2="";
	for(var i=0;i<categoryArr2.length;i++){
		categoryArr2[i] = categoryArr2[i];
		tempStr2 = categoryArr2[i];
		tempStr2 = tempStr2.substring(tempStr2.indexOf(":")+1);
		//alert(tempStr);
		tempArray2[i]= tempStr2;
	}
	var tempStr12="";
	
	$( "#researchkeywordsText").autocomplete({
		//source: categoryArr,
		source: tempArray2,
		//define select handler
		select: function(e, ui) {
			//create formatted data
			var cat = ui.item.value;
			getId(cat,categoryArr2,'researchkeywords');
			
			$("#researchkeywordsText").val(cat);
			//tempStr1 = cat.substring(cat.indexOf(":")+1);
			//alert(tempStr1);
			//tempStr2 = cat.substring(0,cat.indexOf(":"));
			//alert(tempStr2);
		},
		close: function(event, ui) {
			
			
		}
	});
	
	var categoryList3 = '${categoryList}';
	var catStr3 = categoryList3.substring(categoryList3.indexOf('{')+1,categoryList3.indexOf('}'));
	catStr3 = catStr3.replace(/=/g,":");
	//alert(catStr);
	var categoryArr3=catStr3.split(',');
	var tempArray3 = new Array();
	var tempStr3="";
	for(var i=0;i<categoryArr3.length;i++){
		categoryArr3[i] = categoryArr3[i];
		tempStr3 = categoryArr3[i];
		tempStr3 = tempStr3.substring(tempStr3.indexOf(":")+1);
		//alert(tempStr);
		tempArray3[i]= tempStr3;
	}
	var tempStr13="";
	
	$( "#categoriesText").autocomplete({
		//source: categoryArr,
		source: tempArray3,
		//define select handler
		select: function(e, ui) {
			//create formatted data
			var cat = ui.item.value;
			getId(cat,categoryArr3,'categories');
			
			$("#categoriesText").val(cat);
			//tempStr1 = cat.substring(cat.indexOf(":")+1);
			//alert(tempStr1);
			//tempStr2 = cat.substring(0,cat.indexOf(":"));
			//alert(tempStr3);
		},
		close: function(event, ui) {
			
			
		}
	});
	
});
//if(tempStr2=="")
//	$("#category_categoryId").val(tempStr2);
	
function getId(str,arr,imp){
	var key = "";
	var value ="";
	var tempStr="";
	for(var i=0;i<arr.length;i++){
		tempStr = arr[i];
		key=tempStr.substring(0,tempStr.indexOf(":")).replace(/^\s+|\s+$/g, "");
		value = tempStr.substring(tempStr.indexOf(":")+1);
		if(value==str){
			//alert(key);
			$("#"+imp).val(key);
		}
	}
}

$().ready(function() {
	$('#facultyresearchform').validate();
});
</script>
</head>
<body>
	<form:form action="submitAdvancedSearchResearch" modelAttribute="facultyresearch">
	<br></br>
		<div>
			<div class="Faculty">
				<div>
					<div>By Faculty Name</div>
					<div class="value">
						<input type="text" id="facultyText" />
						<form:hidden path="faculty"/>&nbsp;&nbsp;&nbsp;&nbsp;(Example: Karthikeyan Umapathy)
					</div>
				</div><div>&nbsp;</div>
				<div>
					<div class="label">By Title</div>
					<div class="value">
						<form:input path="title" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(Example: Deploying Cloud based databases)
					</div>
				</div><div>&nbsp;</div>
				<div>
					<div class="label">By Description</div>
					<div class="value">
						<form:input path="researchDescription" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(Example: The specific challenges of deploying wide scale database systems over the Cloud)
					</div>
				</div><div>&nbsp;</div>
			<%--	<div>
					<div class="label">By Keyword</div>
					<div class="value">
						<input type="text" id="researchkeywordsText"/>
						<form:hidden path="researchkeywords"/>
					</div>
				</div>--%>
				<div>
					<div class="label">By Category</div>
					<div class="value">
						<input type="text" id="categoriesText"/>
						<form:hidden path="categories"/>&nbsp;&nbsp;&nbsp;&nbsp;(Example: Cloud Computing)
					</div>
				</div><div>&nbsp;</div>
				<div>
					<div class="label">Check for only Active Research</div>
					<div class="checkbox">
						<input type="checkbox"></input>
					</div>
				</div><div>&nbsp;</div>
				<div id="submitFaculty">
					<button id="submitButton">Submit</button>
				</div>
			</div>
		</div>
	</form:form>
</body>